﻿using System.ComponentModel;

namespace Borg.Framework
{
    public class ContextMenuStrip : System.Windows.Forms.ContextMenuStrip
    {
        internal ToolStripItemCollectionHandler tsiCollectionHandler;

        public event MenuItemEventHandler AfterHandleClick;
        public event MenuItemEventHandler BeforeHandleClick;

        public ContextMenuStrip()
        {
            Init();
        }

        public ContextMenuStrip(IContainer container)
            : base(container)
        {
            Init();
        }

        private void Init()
        {
            tsiCollectionHandler = new ToolStripItemCollectionHandler(Items);

            tsiCollectionHandler.BeforeHandleClick += OnBeforeHandleClick;
            tsiCollectionHandler.AfterHandleClick += OnAfterHandleClick;
        }

        protected void OnAfterHandleClick(object sender, MenuItemEventArgs args)
        {
            if (AfterHandleClick != null)
                AfterHandleClick(sender, args);
        }

        protected void OnBeforeHandleClick(object sender, MenuItemEventArgs args)
        {
            if (BeforeHandleClick != null)
                BeforeHandleClick(sender, args);
        }

        public void RemoveActionBehavior(SlotInfo si)
        {
            tsiCollectionHandler.RemoveActionBehavior(si);
        }

        public void RemoveCreateBehavior(SlotInfo si)
        {
            tsiCollectionHandler.RemoveCreateBehavior(si);
        }

        public void RemoveOpenBehavior(SlotInfo si)
        {
            tsiCollectionHandler.RemoveOpenBehavior(si);
        }

        public void RemovePlugBehavior(SlotInfo si)
        {
            tsiCollectionHandler.RemovePlugBehavior(si);
        }

        public void RemoveRegisterBehavior(SlotInfo si)
        {
            tsiCollectionHandler.RemoveRegisterBehavior(si);
        }

        public void SetActionBehavior(SlotInfo si, PlugTypeHandler itemHandler)
        {
            tsiCollectionHandler.SetActionBehavior(si, itemHandler);
        }

        public void SetCreateBehavior(SlotInfo si, PlugTypeHandler itemHandler)
        {
            tsiCollectionHandler.SetCreateBehavior(si, itemHandler);
        }

        public void SetOpenBehavior(SlotInfo si, string itemPath)
        {
            tsiCollectionHandler.SetOpenBehavior(si, itemPath);
        }

        public void SetPlugBehavior(SlotInfo si, PlugHandler itemHandler)
        {
            tsiCollectionHandler.SetPlugBehavior(si, itemHandler);
        }

        public void SetRegisterBehavior(SlotInfo si, PlugTypeHandler itemHandler)
        {
            tsiCollectionHandler.SetRegisterBehavior(si, itemHandler);
        }
    }
}

